{% extends "layout.html" %}

{% block css_m %}


{% endblock %}
{% block js_m %}

{% endblock %}

{% block content_body %}
    <div class="page-jumbotron center-block" style="width: 800px">
        <h1>修改用户名和密码</h1>
    </div>
    <div class="panel-body center-block" style="width: 800px">
        <form method="post" novalidate>
            {% csrf_token %}
            {% for field in form_edit %}

                <div class="form-group" >
                    <label>{{ field.label }}</label>
                    {{ field }}
                    <span class="error_msg">{{ field.errors.0 }}</span>
                </div>

            {% endfor %}

            <button type="submit" class="btn btn-primary" id="btn_conf">提交</button>
            <a class="btn btn-default" href="/home.html/">取 消</a>
        </form>

    </div>








{% endblock %}

{% block content_bottom %}
    <script>
        $(function () {
            $("#id_conf_pwd,#id_new_pwd").bind('input propertychange', function () {
                var pwd = $("#id_new_pwd").val()
                var pwd_conf = $("#id_conf_pwd").val()
                if (pwd !== pwd_conf) {
                    $("#id_conf_pwd").next().text("两次输入的密码不一致！")
                    $("#btn_conf").attr("disabled", "disabled")
                } else {
                     $("#id_conf_pwd").next().text("")
                    $("#btn_conf").removeAttr("disabled")
                }
            });
            $("#id_user_name").blur(function () {
                var user_name = $(this).val()
                $.ajaxSetup({

                data: {csrfmiddlewaretoken: '{{ csrf_token }}'},

            });
                $.ajax({
                        url: '/check_user_name.html/',
                        type: 'POST',
                        data: {
                            'old_user_name': "{{ old_user_name }}",
                            'user_name': user_name,

                        },
                        dataType: 'JSON',
                        success: function (arg) {

                                if(arg["ret"]){
                                    $("#id_user_name").next().text("用户名已被占用！")
                                    $("#btn_conf").attr("disabled", "disabled")

                                }else{
                                    $("#id_user_name").next().text("")
                                    $("#btn_conf").removeAttr("disabled")


                                }




                        }

                    }
                );
            });


        })
    </script>
{% endblock %}